from quto_auto.base.browseroperation import BrowserOperation
from quto_auto.base.browseroperationex import BrowserOperationEx

from quto_auto.base.usebrowser import UseBrowser
from quto_auto.util.exloperation import ExlOpera
from quto_auto.util.yamloperation import YamlOperation


class LoginPage:

    def __init__(self):
        self.ub = UseBrowser()  # 实例化浏览器
        self.bo = BrowserOperation(self.ub.driver)
        self.boex = BrowserOperationEx(self.ub.driver)
        self.exl=ExlOpera()
        self.yo=YamlOperation()
        self.exl.get_sheet('登录用例参数')

    def login(self,username,password):
        self.bo.open_url(self.exl.get_cell(1,1))
        self.bo.input_text('name', self.yo.get_locator('LoginPage','username'), username)
        self.bo.input_text('name', self.yo.get_locator('LoginPage','password'), password)
        self.bo.click('name', self.yo.get_locator('LoginPage','submit'))

    #获取登录成功的信息
    def login_suc_info(self):
        self.boex.change_frame(self.yo.get_locator('LoginPage','frame_main'))    #切进name为main框架
        suc_info=self.bo.get_text('xpath',self.yo.get_locator('LoginPage','suc_info_xpath'))  #获取文本
        return suc_info

    # 获取登录失败的信息
    def login_fail_info(self):
        fail_info = self.bo.get_text('xpath', self.yo.get_locator('LoginPage','fail_info_xpath'))  # 获取文本
        return fail_info


# if __name__ == '__main__':
#     lp=LoginPage()
#     lp.login('admin','admin')